home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume7 / nsubj < prev    next >
Encoding:
Text File  |  1989-06-03  |  13.3 KB  |  517 lines

  1. Newsgroups: comp.sources.misc
  2. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  3. Subject: v07i008: News subject index routines
  4. Reply-To: nelson@uncw.uucp (doom)
  5.  
  6. Posting-number: Volume 7, Issue 8
  7. Submitted-by: nelson@uncw.uucp (doom)
  8. Archive-name: nsubj
  9.  
  10. [PLEASE, people!  This came with no subject line and no information outside
  11. the shar.  This isn't exactly polite.  ++bsa]
  12.  
  13. #! /bin/sh
  14. # This is a shell archive.  Remove anything before this line, then unpack
  15. # it by saving it into a file and typing "sh file".  To overwrite existing
  16. # files, type "sh file -c".  You can also feed this as standard input via
  17. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  18. # will see the following message at the end:
  19. #        "End of archive 1 (of 1)."
  20. # Contents:  MANIFEST Makefile README crontabentry jimsindex.c subj.1
  21. #   subj.c subj.old subjc.8 subjc.c subjn subjn.8
  22. # Wrapped by nelson@uncw on Mon May 22 14:14:03 1989
  23. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  24. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  25.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  26. else
  27. echo shar: Extracting \"'MANIFEST'\" \(486 characters\)
  28. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  29. X   File Name        Archive #    Description
  30. X-----------------------------------------------------------
  31. X MANIFEST                   1    This shipping list
  32. X Makefile                   1    
  33. X README                     1    
  34. X crontabentry               1    
  35. X jimsindex.c                1    
  36. X subj.1                     1    
  37. X subj.c                     1    
  38. X subj.old                   1    
  39. X subjc.8                    1    
  40. X subjc.c                    1    
  41. X subjn                      1    
  42. X subjn.8                    1    
  43. END_OF_FILE
  44. if test 486 -ne `wc -c <'MANIFEST'`; then
  45.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  46. fi
  47. # end of 'MANIFEST'
  48. fi
  49. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  50.   echo shar: Will not clobber existing file \"'Makefile'\"
  51. else
  52. echo shar: Extracting \"'Makefile'\" \(631 characters\)
  53. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  54. XCFLAGS=-O #-DSYSV
  55. XSRC= Makefile README subj.1 subjc.8 subjn.8 subj.c \
  56. Xsubj.old subjc.c jimsindex.c subjn crontabentry
  57. XBINDIR=/usr/local/bin
  58. XMANDIR1=/usr/man/man1
  59. XMANDIR8=/usr/man/man8
  60. X
  61. XOBJS=subj.o subjc.o jimsindex.o
  62. X#Sequent users will know what the following line is, others
  63. X#remove the &
  64. XP=&
  65. Xall: $(P) subj subjc
  66. Xsubj: $(P) subj.o jimsindex.o
  67. X    cc -o subj -s subj.o jimsindex.o
  68. Xsubjc: $(P) subjc.o jimsindex.o
  69. X    cc -o subjc -s subjc.o jimsindex.o
  70. Xinstall: subj subjc
  71. X    mv subj $(BINDIR)
  72. X    mv subjc $(BINDIR)
  73. X    cp subj.1 $(MANDIR1)
  74. X    cp subjc.8 $(MANDIR8)
  75. X    cp subjn.8 $(MANDIR8)
  76. Xclean:
  77. X    rm *.o subj subjc
  78. Xshar: 
  79. X    makekit  -m $(SRC)
  80. X    
  81. END_OF_FILE
  82. if test 631 -ne `wc -c <'Makefile'`; then
  83.     echo shar: \"'Makefile'\" unpacked with wrong size!
  84. fi
  85. # end of 'Makefile'
  86. fi
  87. if test -f 'README' -a "${1}" != "-c" ; then 
  88.   echo shar: Will not clobber existing file \"'README'\"
  89. else
  90. echo shar: Extracting \"'README'\" \(1274 characters\)
  91. sed "s/^X//" >'README' <<'END_OF_FILE'
  92. XA couple of handy programs for dealing with subjects in netnews
  93. X("Now where was that article I thought I didn't want to read?").
  94. X"Subj" is a standalone C program which emulates
  95. X% cd <desired_news_directory>;head * | egrep '==>|ubject:'
  96. Xbut is (at least on our machine) faster; plus it puts the filename
  97. Xand the subject-line on the same line.
  98. X"Subjc" is a modified version which accepts a file of file-names
  99. Xand sorta does the same thing.  See the script "subjn" for
  100. Xuse of subjc.  It's an overnight package to put up "/tmp/subjnews"
  101. Xfor later perusal or fgrepping.
  102. X/*Uses the "readdir" stuff of BSD, so probably not very (at all)
  103. Xportable to SYSV.*/
  104. XActually I did go over to a couple of SYSV boxes (3b2/300's
  105. XR2.0 and R3.1) and make it work with SYSV (gad! how long has
  106. Xit been since I had to suffer SYSV?)...  The pertinent 
  107. Xcode is #ifdeffed SYSV.
  108. XThe man pages and Makefile are probably gross overkill for a couple
  109. Xof 50-line programs, but ... just wanted to do it right.  Spent
  110. Xmuch more time on getting the package together than originally
  111. Xspent writing the programs ... but, what the heck ...
  112. XP.S. vi with sw=4, etc.
  113. X-------------
  114. XJim Nelson,UNC-Wilmington,Mathematical Sciences Dept, 919-395-3300
  115. Xnelson@uncw.uucp or nelson@ecsvax.uncecs.edu or nelson@ecsvax.bitnet
  116. END_OF_FILE
  117. if test 1274 -ne `wc -c <'README'`; then
  118.     echo shar: \"'README'\" unpacked with wrong size!
  119. fi
  120. # end of 'README'
  121. fi
  122. if test -f 'crontabentry' -a "${1}" != "-c" ; then 
  123.   echo shar: Will not clobber existing file \"'crontabentry'\"
  124. else
  125. echo shar: Extracting \"'crontabentry'\" \(27 characters\)
  126. sed "s/^X//" >'crontabentry' <<'END_OF_FILE'
  127. X34 7 * * * /usr/uncw/subjn
  128. END_OF_FILE
  129. if test 27 -ne `wc -c <'crontabentry'`; then
  130.     echo shar: \"'crontabentry'\" unpacked with wrong size!
  131. fi
  132. # end of 'crontabentry'
  133. fi
  134. if test -f 'jimsindex.c' -a "${1}" != "-c" ; then 
  135.   echo shar: Will not clobber existing file \"'jimsindex.c'\"
  136. else
  137. echo shar: Extracting \"'jimsindex.c'\" \(436 characters\)
  138. sed "s/^X//" >'jimsindex.c' <<'END_OF_FILE'
  139. Xjimsindex(a,b)
  140. Xchar *a, *b;
  141. X{
  142. X    int i,j;
  143. X    if(!*a || !*b)return -1;
  144. X    for(i=0;a[i];i++)
  145. X    {
  146. X        for(j=0;;j++)
  147. X        {
  148. X/*            printf("compare %x and %x\n",a[i+j],b[j]);*/
  149. X            if(a[i+j]!=b[j])break;
  150. X        }
  151. X        if(!b[j])return i;
  152. X    }
  153. X    return -1;
  154. X}
  155. X/*
  156. Xchar *x = "Now is the time for all zorkmids";
  157. Xmain()
  158. X{
  159. X    char y[132];
  160. X    int i;
  161. X    for(;;){
  162. X        gets(y);
  163. X        i=jimsindex(x,y);
  164. X        printf("%s,%d\n",x,i);
  165. X        y[0]=0;
  166. X        i=jimsindex(x,y);
  167. X        printf("%s,%d\n",x,i);
  168. X    }
  169. X}
  170. X*/    
  171. END_OF_FILE
  172. if test 436 -ne `wc -c <'jimsindex.c'`; then
  173.     echo shar: \"'jimsindex.c'\" unpacked with wrong size!
  174. fi
  175. # end of 'jimsindex.c'
  176. fi
  177. if test -f 'subj.1' -a "${1}" != "-c" ; then 
  178.   echo shar: Will not clobber existing file \"'subj.1'\"
  179. else
  180. echo shar: Extracting \"'subj.1'\" \(623 characters\)
  181. sed "s/^X//" >'subj.1' <<'END_OF_FILE'
  182. X.TH SUBJ 1 LOCAL
  183. X.SH NAME
  184. Xsubj \- Find "Subject:" line in netnews articles
  185. X.SH SYNOPSIS
  186. X.B subj
  187. X[
  188. X.B -d 
  189. X] 
  190. X.SH DESCRIPTION
  191. X.B Subj
  192. Xfinds "Subject:" lines in all files in a directory.  Finds only
  193. Xfirst match, thus saving time.  The single option -d allows
  194. Xdumping the "Date:" line in addition.
  195. X.SH EXAMPLE
  196. Xcd /usr/spool/news/comp/sources/unix; subj
  197. X.SH BUGS
  198. XA clever combination of head, fgrep, cut, join, etc., probably
  199. Xcould do the same job in a shell script, but, what the heck,
  200. Xit's only fifty or so lines of C code ...
  201. X.SH SEE ALSO
  202. Xsubjc(8), subjn(1)
  203. X.SH AUTHOR
  204. XJim Nelson,  nelson@uncw.uucp  nelson@ecsvax.uncecs.edu
  205. END_OF_FILE
  206. if test 623 -ne `wc -c <'subj.1'`; then
  207.     echo shar: \"'subj.1'\" unpacked with wrong size!
  208. fi
  209. # end of 'subj.1'
  210. fi
  211. if test -f 'subj.c' -a "${1}" != "-c" ; then 
  212.   echo shar: Will not clobber existing file \"'subj.c'\"
  213. else
  214. echo shar: Extracting \"'subj.c'\" \(1873 characters\)
  215. sed "s/^X//" >'subj.c' <<'END_OF_FILE'
  216. X#include <sys/types.h>
  217. X#include <sys/dir.h>
  218. Xstruct direct zork;
  219. X#include <stdio.h>
  220. X#ifdef SYSV
  221. Xextern char *sys_errlist[];
  222. Xopendir(p)
  223. Xchar *p;
  224. X{
  225. X    int i;
  226. X    extern int errno;
  227. X    extern char *errmsg;
  228. X    i= open(p,0);
  229. X    if(i<0){
  230. X        fprintf(stderr,"errno=%d %s\n",errno,sys_errlist[errno]);
  231. X        fprintf(stderr,"in opendir, i=%d\n",i);
  232. X        exit(7);
  233. X    }
  234. X    return i;
  235. X}
  236. Xunion{
  237. Xstruct direct crundy;
  238. Xchar moobus[17];
  239. X} noogle;
  240. Xstruct direct *readdir(fd)
  241. Xint fd;
  242. X{
  243. X    int i;
  244. X    /*
  245. X    loop:
  246. X    i=read(fd,&(noogle.crundy),sizeof(struct direct));
  247. X
  248. X    if(i<=0)return (struct direct *)0;
  249. X    else
  250. X    {
  251. X    if(noogle.crundy.d_ino==0)goto loop;
  252. X    if(noogle.crundy.d_name[0]=='.')goto loop;
  253. X    */
  254. X    do{
  255. X    i=read(fd,&(noogle.crundy),sizeof(struct direct));
  256. X
  257. X    if(i<=0)return (struct direct *)0;
  258. X    } while(
  259. X        noogle.crundy.d_ino==0 ||
  260. X        noogle.crundy.d_name[0]=='.'
  261. X        );
  262. X    noogle.crundy.d_name[14]=0;
  263. X    return  &(noogle.crundy);
  264. X}
  265. X#endif
  266. X
  267. X
  268. Xmain(argc,argv)
  269. Xchar **argv;
  270. X{
  271. X
  272. X    char *line, *malloc(), *fgets();
  273. X#ifdef SYSV
  274. X    int dirp, opendir();
  275. X    struct direct *readdir(), *p;
  276. X#else
  277. X    DIR *dirp;
  278. X    struct direct *p;
  279. X#endif
  280. X    FILE *fp;
  281. X    int i, dodate, found, tofind;
  282. X    struct direct dir;
  283. X
  284. X    dodate=0;
  285. X    line = malloc(513);
  286. X    if(line==(char *)0)error(1);
  287. X    if(argc>=2)
  288. X        for(i=1;i<argc;i++)
  289. X        {
  290. X            if(!strcmp(argv[i],"-d"))dodate=1;
  291. X        }
  292. X
  293. X    p= &dir;
  294. X    tofind=1;
  295. X    if(dodate)tofind++;
  296. X    dirp=opendir(".");
  297. X    if(dirp==NULL)error(2);
  298. X    while  (p=readdir(dirp)) {
  299. X        fp=fopen(p->d_name,"r");
  300. X        if(fp==(FILE *)0)error(3);
  301. X        found=0;
  302. X        for(;;){
  303. X            if(fgets(line,132,fp)!=line)break;
  304. X            if(jimsindex(line,"ubject:")>=0)
  305. X            {
  306. X                printf("%s:%s",p->d_name,line);
  307. X                found++;
  308. X                if(found >= tofind)break;
  309. X            }
  310. X            if(dodate)
  311. X                if(jimsindex(line,"Date")>=0)
  312. X                {
  313. X                    printf("%s:%s",p->d_name,line);
  314. X                    found++;
  315. X                    if(found>=tofind)break;
  316. X                }
  317. X        }
  318. X        if(fp)i=fclose(fp);
  319. X        if(i<0)error(4);
  320. X    }
  321. X    exit(0);
  322. X}
  323. Xerror(i)
  324. X{
  325. X    fprintf(stderr,"error %d\n",i);
  326. X    exit(i);
  327. X}
  328. END_OF_FILE
  329. if test 1873 -ne `wc -c <'subj.c'`; then
  330.     echo shar: \"'subj.c'\" unpacked with wrong size!
  331. fi
  332. # end of 'subj.c'
  333. fi
  334. if test -f 'subj.old' -a "${1}" != "-c" ; then 
  335.   echo shar: Will not clobber existing file \"'subj.old'\"
  336. else
  337. echo shar: Extracting \"'subj.old'\" \(318 characters\)
  338. sed "s/^X//" >'subj.old' <<'END_OF_FILE'
  339. X#! /bin/sh
  340. Xcase $1 in
  341. X    "") dir=.;;
  342. X    *) dir=$1;;
  343. Xesac
  344. X     cd $dir
  345. X    for i in `ls -t`;do
  346. X        if [ -d $i ]
  347. X        then
  348. X            echo ${i}': ****directory****'
  349. X#            cd $i;/bin/sh /usr/uncw/subj
  350. X#            echo ${i}'******end******'
  351. X        fi
  352. X        if [ -f $i ]
  353. X        then
  354. X            echo -n "$i:";head $i|if fgrep ubject
  355. X            then
  356. X            :
  357. X            else
  358. X            echo
  359. X            fi
  360. X        fi
  361. X    done
  362. END_OF_FILE
  363. if test 318 -ne `wc -c <'subj.old'`; then
  364.     echo shar: \"'subj.old'\" unpacked with wrong size!
  365. fi
  366. # end of 'subj.old'
  367. fi
  368. if test -f 'subjc.8' -a "${1}" != "-c" ; then 
  369.   echo shar: Will not clobber existing file \"'subjc.8'\"
  370. else
  371. echo shar: Extracting \"'subjc.8'\" \(722 characters\)
  372. sed "s/^X//" >'subjc.8' <<'END_OF_FILE'
  373. X.TH SUBJC 1 LOCAL
  374. X.SH NAME
  375. Xsubjc \- Find "Subject:" line in netnews articles
  376. X.SH SYNOPSIS
  377. X.B subjc filename
  378. X.SH DESCRIPTION
  379. X.B Subjc
  380. Xfinds "Subject:" lines in all files in a file of filenames.
  381. XFinds only
  382. Xfirst match, thus saving time.
  383. X.SH EXAMPLE
  384. X.sp
  385. X#!/bin/sh
  386. X.sp
  387. X/usr/bin/find /usr/spool/news -type f -print >/tmp/sub1jnews
  388. X.sp
  389. Xdate > /tmp/subjnews
  390. X.sp
  391. X/usr/local/bin/subjc /tmp/sub1jnews | /usr/bin/sort >> /tmp/subjnews
  392. X.sp
  393. Xrm -f /tmp/sub1jnews
  394. X.SH BUGS
  395. XA clever combination of head, fgrep, cut, join, etc., probably
  396. Xcould do the same job in a shell script, but, what the heck,
  397. Xit's only fifty or so lines of C code ...
  398. X.SH SEE ALSO
  399. Xsubj(1), subjn(1)
  400. X.SH AUTHOR
  401. XJim Nelson,  nelson@uncw.uucp  nelson@ecsvax.uncecs.edu
  402. END_OF_FILE
  403. if test 722 -ne `wc -c <'subjc.8'`; then
  404.     echo shar: \"'subjc.8'\" unpacked with wrong size!
  405. fi
  406. # end of 'subjc.8'
  407. fi
  408. if test -f 'subjc.c' -a "${1}" != "-c" ; then 
  409.   echo shar: Will not clobber existing file \"'subjc.c'\"
  410. else
  411. echo shar: Extracting \"'subjc.c'\" \(743 characters\)
  412. sed "s/^X//" >'subjc.c' <<'END_OF_FILE'
  413. X#include <stdio.h>
  414. X#define SZ 512 /*line lengths*/
  415. Xmain(argc,argv)
  416. Xchar *argv[];
  417. X{
  418. X    FILE *fn, *fp;
  419. X    char *line, *file, *fgets(), *malloc();
  420. X    int i,k;
  421. X
  422. X    line = malloc(SZ+1);
  423. X    if(line==(char *)0)exit(1);
  424. X    file = malloc(SZ+1);
  425. X    if(file==(char *)0)exit(2);
  426. X
  427. X    if(argc>=2)fn=fopen(argv[1],"r");
  428. X    else exit(3);
  429. X    if(fn==(FILE *)0)exit(1);
  430. X    while( fgets(file,SZ,fn)==file){
  431. X        for(i=0;file[i]&&i<SZ;i++)if(file[i]=='\n')file[i]=0;
  432. X        fp=fopen(file,"r");
  433. X        if(fp==NULL){
  434. X            printf("cannot open: %s\n",file);
  435. X            exit(2);
  436. X        }
  437. X        for(i=0;i<40;i++){
  438. X            if( fgets(line,SZ,fp)!=line)break;
  439. X            if(*line)
  440. X                if( (k=jimsindex(line,"ubject:"))>0)
  441. X                {
  442. X                    printf("%s\t%s",file+15,line+k+7);
  443. X                    break;
  444. X                }
  445. X        }
  446. X        if(fp!=NULL){i=fclose(fp);if(i<0)exit(4);}
  447. X    }
  448. X}
  449. END_OF_FILE
  450. if test 743 -ne `wc -c <'subjc.c'`; then
  451.     echo shar: \"'subjc.c'\" unpacked with wrong size!
  452. fi
  453. # end of 'subjc.c'
  454. fi
  455. if test -f 'subjn' -a "${1}" != "-c" ; then 
  456.   echo shar: Will not clobber existing file \"'subjn'\"
  457. else
  458. echo shar: Extracting \"'subjn'\" \(182 characters\)
  459. sed "s/^X//" >'subjn' <<'END_OF_FILE'
  460. X#!/bin/sh
  461. X/usr/bin/find /usr1/NET/News -type f -print >/tmp/sub1jnews
  462. Xdate > /tmp/subjnews
  463. X/usr/local/bin/subjc /tmp/sub1jnews | /usr/bin/sort >> /tmp/subjnews
  464. Xrm -f /tmp/sub1jnews
  465. X
  466. END_OF_FILE
  467. if test 182 -ne `wc -c <'subjn'`; then
  468.     echo shar: \"'subjn'\" unpacked with wrong size!
  469. fi
  470. # end of 'subjn'
  471. fi
  472. if test -f 'subjn.8' -a "${1}" != "-c" ; then 
  473.   echo shar: Will not clobber existing file \"'subjn.8'\"
  474. else
  475. echo shar: Extracting \"'subjn.8'\" \(453 characters\)
  476. sed "s/^X//" >'subjn.8' <<'END_OF_FILE'
  477. X.TH SUBJN 1 LOCAL
  478. X.SH NAME
  479. Xsubjn \- Find "Subject:" line in netnews articles
  480. X.SH SYNOPSIS
  481. X.B subjn filename
  482. X.SH DESCRIPTION
  483. X.B Subjn
  484. Xis a shell script driver for subjc, which see.
  485. X.SH BUGS
  486. XA clever combination of head, fgrep, cut, join, etc., probably
  487. Xcould do the same job in a shell script, but, what the heck,
  488. Xit's only fifty or so lines of C code ...
  489. X.SH SEE ALSO
  490. Xsubjc(1), subj(1)
  491. X.SH AUTHOR
  492. XJim Nelson,  nelson@uncw.uucp  nelson@ecsvax.uncecs.edu
  493. END_OF_FILE
  494. if test 453 -ne `wc -c <'subjn.8'`; then
  495.     echo shar: \"'subjn.8'\" unpacked with wrong size!
  496. fi
  497. # end of 'subjn.8'
  498. fi
  499. echo shar: End of archive 1 \(of 1\).
  500. cp /dev/null ark1isdone
  501. MISSING=""
  502. for I in 1 ; do
  503.     if test ! -f ark${I}isdone ; then
  504.     MISSING="${MISSING} ${I}"
  505.     fi
  506. done
  507. if test "${MISSING}" = "" ; then
  508.     echo You have the archive.
  509.     rm -f ark[1-9]isdone
  510. else
  511.     echo You still need to unpack the following archives:
  512.     echo "        " ${MISSING}
  513. fi
  514. ##  End of shell archive.
  515. exit 0
  516.  
  517.